from pyecharts import *
from random import *
import time


def random_point():
    return [randint(1, 10) for _ in range(6)]


def reflesh(func):
    def inner():
        while 1:
            func()
            time.sleep(5)
            print('sleep 5 sec.')
    return inner


def line1():
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = random_point()
    v2 = random_point()
    line = Line("折线图示例")
    line.add("商家A", attr, v1, mark_point=["average"])
    line.add("商家B", attr, v2, is_smooth=True, mark_line=["max", "average"])
    line.render()


def line2():
    line = Line("折线图-面积图示例")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = random_point()
    v2 = random_point()
    line.add(
        "商家A",
        attr,
        v1,
        is_fill=True,
        line_opacity=0.2,
        area_opacity=0.4,
        symbol=None,
    )
    line.add(
        "商家B",
        attr,
        v2,
        is_fill=False,
        area_color="#000",
        area_opacity=0.3,
        is_smooth=True,
    )
    line.render()


def line3():
    line = Line("折线图示例")
    attr = ["a", "b", "c", "d", "e", "f"]
    line.add("商家A", attr, [random.randint(1, 10) for _ in range(6)])
    line.add(
        "商家B",
        attr,
        [random.randint(1, 20) for _ in range(6)],
        yaxis_type="log",
    )
    line.render()


def line4():
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    attr2 = ["a", "b", "c", "d", "e", "f"]

    bar_1 = Bar("2012 年销量", "数据纯属虚构")
    bar_1.add("春季", attr, [randint(10, 100) for _ in range(6)])
    bar_1.add("夏季", attr, [randint(10, 100) for _ in range(6)])
    bar_1.add("秋季", attr, [randint(10, 100) for _ in range(6)])
    bar_1.add("冬季", attr, [randint(10, 100) for _ in range(6)])

    bar_5 = Bar("2016 年销量", "数据纯属虚构")
    bar_5.add("春季", attr2, [randint(10, 100) for _ in range(6)])
    bar_5.add("夏季", attr2, [randint(10, 100) for _ in range(6)])
    bar_5.add("秋季", attr2, [randint(10, 100) for _ in range(6)])
    bar_5.add("冬季", attr2, [randint(10, 100) for _ in range(6)], is_legend_show=True)

    timeline = Timeline(is_auto_play=False, timeline_bottom=0)
    timeline.add(bar_1, '2012 年')
    timeline.add(bar_5, '2016 年')
    timeline.render()


line4()